<template>
  <div class="app-container">
    <el-form ref="form" :model="list" label-width="120px">
      <el-form-item label="计划ID">
        <el-input v-model="list.planId" readonly />
      </el-form-item>
      <el-form-item label="计划名称">
        <el-input v-model="list.planName" readonly />
      </el-form-item>
      <el-form-item label="描述">
        <el-input v-model="list.requirement" readonly />
      </el-form-item>
      <el-form-item label="计划招聘人数">
        <el-input v-model="list.num" readonly />
      </el-form-item>
      <el-form-item label="实验室名">
        <el-input v-model="list.department" readonly />
      </el-form-item>
      <el-form-item label="本人技能描述">
        <el-input v-model="list.tbDescribe" />
      </el-form-item>
      <el-form-item label="申请人">
        <el-input v-model="list.userName1" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit1">确定报名</el-button>
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import qs from 'qs'

export default {
  data() {
    return {
      list: {
        readonly: true
      }
    }
  },
  created() {
    this.fatchDataById()
  },
  methods: {
    fatchDataById() {
      var _this = this
      var id = this.$route.params.id
      this.$axios.get('/plan/getPlanById?id=' + id)
        .then(function(res) {
          _this.list = res.data
        })
    },
    edit1(id) { // 审核通过请求加1
      this.$axios.put('plan/edit3?id=' + id)
        .then(res => {
          this.fetchData()
        })
    },
    onSubmit() {
      this.$axios.post(`/enlist/addEnlist`, qs.stringify({
        'planId': this.list.planId,
        'planName': this.list.planName,
        'tbDescribe': this.list.tbDescribe,
        'studentName': this.list.userName1
      }), {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
        }
      })
        .then(res => {
          this.$message({
            message: '操作成功！',
            type: 'success'
          })
          this.edit1(this.$route.params.id)
          this.$router.push('/baoming/baomingList')
        })
    },
    onCancel() {
      this.$message({
        message: '取消成功！',
        type: 'warning'
      })
      this.$router.push('/baoming/baomingList')
    },
    onSubmit1() {
      this.$confirm('报名该实验室', '是否报名?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        this.onSubmit()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    }
  }
}
</script>

